#include "linux_def.h"
#include "core.h"
#include "event.h"

ssize_t g_recv(connection_t *c, char *buf, size_t size)
{
	ssize_t	n;
	event_t	*rev;

	rev = c->read;

	do {
		n = recv(c->fd, buf, size, 0);
		if (n == 0){
			rev->ready = 0;
			return;
		}else if (n > 0){
			if ((size_t)n < size)
				rev->ready = 0;
			return n;
		}

		if (errno == EAGAIN || errno == EINTR)
			n = EAGAIN;
		else
			break;
	}while(errno == EINTR);

	rev->ready = 0;

	if (verbose)
		printf("%s, %d, %s\n", __FILE__, __LINE__, __func__);

	return n;
}
